package chart;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.chart.BubbleChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;

// 气泡图(点图,形状只有气泡)
public class BubbleChartdemo extends Application {
	private Pane root = new Pane();
	private NumberAxis x = new NumberAxis("月份", 0, 12, 1);
	private NumberAxis y = new NumberAxis("销量", 0, 12, 1);
	private BubbleChart<Number, Number> bc = new BubbleChart<>(x, y);	// x,y必须为NumberAxis类
	
	public static void main(String[] args) {
		launch(args);
	}
	
	@Override
	public void start(Stage stage) throws Exception {
		
		bc.setStyle("-fx-background-color: lightskyblue");
		bc.setPrefSize(400, 400);
		
		XYChart.Data<Number, Number> data1 = new XYChart.Data<>(1, 2);
		data1.setExtraValue(0.2);		// 设置气泡半径
		XYChart.Data<Number, Number> data2 = new XYChart.Data<>(3, 4);
		data2.setExtraValue(0.2);
		XYChart.Data<Number, Number> data3 = new XYChart.Data<>(6, 3);
		data3.setExtraValue(0.2);
		XYChart.Data<Number, Number> data4 = new XYChart.Data<>(8, 7);
		data4.setExtraValue(0.2);
		
		XYChart.Series<Number, Number> xy1 = new XYChart.Series<>();
		xy1.setName("销量");
		xy1.getData().add(data1);
		xy1.getData().add(data2);
		xy1.getData().add(data3);
		xy1.getData().add(data4);
		
		bc.getData().add(xy1);
		root.getChildren().add(bc);
		
		Scene scene = new Scene(root, 400, 400);
		stage.setScene(scene);
		stage.show();
	}
}
